package cn.iocoder.yudao.module.liveprice.controller.app;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.liveprice.apihttp.NowApiTypeEnum;
import cn.iocoder.yudao.module.liveprice.service.IotDbApiService;
import cn.iocoder.yudao.module.liveprice.service.LivePriceApiService;
import cn.iocoder.yudao.module.liveprice.service.PriceBroadcast;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "查询时价信息")
@RestController
@RequestMapping("/live/price")
@Validated
@Slf4j
public class AppLivePriceController {

    @Autowired
    private PriceBroadcast priceBroadcast;
    @Autowired
    private IotDbApiService iotDbApiService;
    @Autowired
    private LivePriceApiService livePriceApiService;

    @GetMapping("/query")
    public CommonResult<Map<String, Object>> queryTest() {
        return success(priceBroadcast.broadcastPrice());
    }
    @GetMapping("/init-iotdb")
    public void initIotdb() {
        iotDbApiService.init();
    }
    @GetMapping("/inset")
    public void insert() {
        livePriceApiService.getLivePriceNowApi(NowApiTypeEnum.GOLD_GRAM.getType());
        livePriceApiService.getLivePriceNowApi(NowApiTypeEnum.SILVER_GRAM.getType());
        livePriceApiService.getLivePriceNowApi(NowApiTypeEnum.PLATINUM_GRAM.getType());
        livePriceApiService.getLivePriceNowApi(NowApiTypeEnum.PALLADIUM_GRAM.getType());
    }
}
